package com.tl.mq.rocket_mq;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class RocketMqProducer {

    @Resource
    private RocketMQTemplate rocketMQTemplate;
    public String topic = "img_topic";

    @PostMapping(value = "/send")
    public SendResult sendMsg(String msg){
        Message<String> message = MessageBuilder.withPayload(msg).build();
        SendResult sendResult = rocketMQTemplate.syncSend(topic,message);
        return sendResult;
    }


}
